#!/usr/bin/python
# -*- coding: UTF-8 -*-
# author : qianqiang
 
import smtplib
import sys,getopt,os
from exchangelib import Account,Credentials,Message,Mailbox,HTMLBody
reload(sys)
sys.setdefaultencoding('utf-8') 
subject=""
content=""
receive_email=""
mail_user="ares"    #用户名
send_mail="ares@jd.com"
mail_pass="wyqnj0624#HEJIU" 
opts, args = getopt.getopt(sys.argv[1:], "s:m:e:", ["subject=", "message=","email="])
for o,a in opts:
    if o in("-s", "--subject"):
        subject=a
    if o in("-m", "--message"):
        content=a
    if o in("-e","--email"):
	receive_email=a
if len(subject)==0 or len(content)==0 or len(receive_email)==0 or len(mail_pass)==0:
	print "参数错误"
	sys.exit(1) 
credentials = Credentials(mail_user, mail_pass)
account = Account(send_mail, credentials=credentials, autodiscover=True)
m = Message(
        account=account,#之前申明的账户
        subject=subject,
        body=HTMLBody(content),
        to_recipients = [Mailbox(email_address=receive_email)])
m.send()
print "邮件发送成功"